package com.huabo.system.service.impl;

import com.hbfk.entity.DealUserToken;
import com.hbfk.entity.TblStaffUtil;
import com.hbfk.util.PageInfo;
import com.huabo.system.config.DateBaseConfig;
import com.huabo.system.mysql.entity.FindMySql;
import com.huabo.system.mysql.entity.TblInteriorExpertMySql;
import com.huabo.system.mysql.mapper.TblInteriorExpertMySqlDao;
import com.huabo.system.oracle.entity.Find;
import com.huabo.system.oracle.entity.TblInteriorExpert;
import com.huabo.system.oracle.mapper.TblInteriorExpertDao;
import com.huabo.system.service.TblInteriorExpertService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TblInteriorExpertServiceImpl implements TblInteriorExpertService {

    @Resource
    private TblInteriorExpertDao tblInteriorExpertDao;
    @Resource
    private TblInteriorExpertMySqlDao tblInteriorExpertMySqlDao;

    @Override
    public TblInteriorExpert findInterior(TblInteriorExpert interior) {
        List<TblInteriorExpert> tblInterior = tblInteriorExpertDao.findInterior(interior);
        return null;
    }

    @Override
    public TblInteriorExpertMySql findMySqlInterior(TblInteriorExpertMySql interior) {
        List<TblInteriorExpertMySql> tblInterior = tblInteriorExpertMySqlDao.findInterior(interior);
        return null;
    }

    @Override
    public void save(TblInteriorExpert tie) {
        tblInteriorExpertDao.insertInteriorExpert(tie);
    }

    @Override
    public void saveMySql(TblInteriorExpert tie) {
        tblInteriorExpertMySqlDao.insertInteriorExpert(tie);
    }

    @Override
    public void update(TblInteriorExpert tblinter) {
        tblInteriorExpertDao.updateInteriorExpert(tblinter);
    }

    @Override
    public void updateMySql(TblInteriorExpert tblinter) {
        tblInteriorExpertMySqlDao.updateInteriorExpert(tblinter);
    }

//    @Override
//    public String delectId(String id) {
//        tblInteriorExpertDao.deleteByINTERIORID(id);
//        return id;
//    }

    @Override
    public Map<String, Object> getExperList(Find find, String staffId, Integer pageNumber, Integer pageSize, String token) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        try {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            BigDecimal orgid = user.getCurrentOrg().getOrgid();
            PageInfo<TblInteriorExpert> pageInfo = new PageInfo<TblInteriorExpert>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            pageInfo.setTlist(tblInteriorExpertDao.selectListByPageInfoo(pageInfo, orgid, find));
            pageInfo.setTotalRecord(tblInteriorExpertDao.selectListByPageInfoCount(pageInfo, orgid, find));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return resultMap;
    }

    @Override
    public Map<String, Object> getMySqlExperList(Find find, String staffId, Integer pageNumber, Integer pageSize, String token) {
        Map<String, Object> resultMap = new HashMap<String, Object>(0);
        try {
            TblStaffUtil user = DealUserToken.parseUserToken(token);
            BigDecimal orgid = user.getCurrentOrg().getOrgid();
            PageInfo<TblInteriorExpertMySql> pageInfo = new PageInfo<TblInteriorExpertMySql>();
            pageInfo.setCurrentPage(pageNumber);
            pageInfo.setPageSize(pageSize);
            pageInfo.setTlist(tblInteriorExpertMySqlDao.selectListByPageInfoo(pageInfo, orgid, find));
            pageInfo.setTotalRecord(tblInteriorExpertMySqlDao.selectListByPageInfoCount(pageInfo, orgid, find));
            resultMap.put("code", "1");
            resultMap.put("msg", "访问接口成功");
            resultMap.put("data", pageInfo);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return resultMap;
    }

    @Override
    public TblInteriorExpert findInteriorExpertId(BigDecimal userid) {
        List<TblInteriorExpert> list = this.tblInteriorExpertDao.findByRid(userid);
        return list != null && list.size() > 0 ? (TblInteriorExpert) list.get(0) : null;
    }

    @Override
    public TblInteriorExpertMySql findMySqlInteriorExpertId(BigDecimal userid) {
        List<TblInteriorExpertMySql> list = this.tblInteriorExpertMySqlDao.findByRid(userid);
        return list != null && list.size() > 0 ? (TblInteriorExpertMySql) list.get(0) : null;
    }

    @Override
    public Map<String, Object> removeNbzj(BigDecimal interiorid) {
        if (DateBaseConfig.DATABASETYPE.equals("Oracle")) {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                //TblStaffUtil staff = DealUserToken.parseUserToken(token);
                this.tblInteriorExpertDao.deleteNbzj(interiorid);
                resultMap.put("code", "1");
                resultMap.put("msg", "删除成功！");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        } else {
            Map<String, Object> resultMap = new HashMap<String, Object>(0);
            try {
                //TblStaffUtil staff = DealUserToken.parseUserToken(token);
                this.tblInteriorExpertMySqlDao.deleteNbzj(interiorid);
                resultMap.put("code", "1");
                resultMap.put("msg", "删除成功！");
            } catch (Exception e) {
                e.printStackTrace();
            }
            return resultMap;
        }
    }

//    @Override
//    public TblInteriorExpert save(TblInteriorExpert interior) {
//        return tblInteriorExpertDao.save(interior);
//
//    }
}
